<?php

/**
 * Session 类 [用户,登录时间,IP记录]
 *
 * @author Shaun
 */

namespace Utility\Session;

use Zend\Session\Container;

class Session extends Container {

    public $username;
    public $userid;
    public $time;
    public $ip;

    public function __construct() {
        parent::__construct();
        $this->username = parent::offsetGet('username');
        $this->userid = parent::offsetGet('userid');
        $this->time = parent::offsetGet('time');
        $this->ip = parent::offsetGet('ip');
    }

    public function __destruct() {
        if ($this->username) {
            parent::offsetSet('username', $this->username);
            //$_SESSION['username'] = $this->username;
        }
        if ($this->userid) {
            parent::offsetSet('userid', $this->userid);
            //$_SESSION['userid'] = $this->userid;
        }
        if ($this->time) {
            parent::offsetSet('time', $this->time);
            //$_SESSION['time'] = $this->time;
        }
        if ($this->ip) {
            parent::offsetSet('ip', $this->ip);
            //$_SESSION['ip'] = $this->ip;
        }
    }

    public function clear() {

        parent::offsetUnset('username');
        parent::offsetUnset('userid');
        parent::offsetUnset('time');
        parent::offsetUnset('ip');

        $this->time = null;
        $this->userid = null;
        $this->username = null;
        $this->ip = null;
    }

}
